package com.zhengtoudai.ui.presenter;

import android.content.Context;

import com.zhengtoudai.global.Config;
import com.zhengtoudai.http.HttpApi;
import com.zhengtoudai.injector.PerActivity;
import com.zhengtoudai.ui.bean.Result;
import com.zhengtoudai.ui.bean.TransferDetail;
import com.zhengtoudai.ui.view.TransferDetailView;
import com.zhengtoudai.util.AbToastUtil;

import javax.inject.Inject;

import rx.Observer;
import rx.functions.Action0;

/**
 * Created by Administrator on 2016/9/1 0001.
 */
@PerActivity
public class TransferDetailPresenterImpl extends BasePresenterImpl<TransferDetailView> implements TransferDetailPresenter {

    private  Context mContext;
    @Inject
    public TransferDetailPresenterImpl(Context mContext){
        this.mContext=mContext;
    }
    @Override
    public void TransferDetail(String borrowTransId) {
        mSubscription=HttpApi.getInstance().TransferDetail(borrowTransId)
                .doOnSubscribe(new Action0() {
                    @Override
                    public void call() {
                        mView.showDetailDialog();
                    }
                }).subscribe(new Observer<Result<TransferDetail>>() {
            @Override
            public void onCompleted() {
                mView.dismissDetailDialog();
            }

            @Override
            public void onError(Throwable e) {
                mView.onDetailFailure(e);
                mView.dismissDetailDialog();
            }

            @Override
            public void onNext(Result<TransferDetail> result) {
                if (result.getCode()== Config.SUCCESSFUL_CODE){
                    mView.onDetailResult(result.getResult());
                }else{
                    AbToastUtil.showToast(mContext,result.getMessage());
                }
            }
        });
    }
}
